package org.core.tliaswebmanagement.controller;

import lombok.extern.slf4j.Slf4j;
import org.core.tliaswebmanagement.pojo.Emp;
import org.core.tliaswebmanagement.pojo.LoginInfo;
import org.core.tliaswebmanagement.pojo.Result;
import org.core.tliaswebmanagement.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private EmpService  empService;

    @PostMapping
    public Result login(@RequestBody Emp emp) {
        log.info("登录请求:{}",emp);
        LoginInfo info = empService.login(emp);
        if(info == null){
            log.info("登录失败");
            return Result.error("用户名或密码错误");
        }
        log.info("登录成功,员工信息：{}",info);
        return Result.success(info);
    }
}
